wordcloud

生成词云

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
import wordcloud

os.chdir("D:/")


w = wordcloud.WordCloud()
w.generate(s) # <wordcloud.wordcloud.WordCloud object at 0x000001E9B38161D0>
w.to_file("wordcloud.png")


w = wordcloud.WordCloud(font_path="msyh.ttc")
w.generate(s) # <wordcloud.wordcloud.WordCloud object at 0x000001E9C6B68B70>
w.to_file("wordcloud.png")


w.generate(" ".join(jieba.lcut(s)))#<wordcloud.wordcloud.WordCloud object at 0x000001E9C6B68B70>
w.to_file("wordcloud.png")


w = wordcloud.WordCloud(font_path="msyh.ttc", width=1000, height=700)
w.generate(" ".join(jieba.lcut(s))) # <wordcloud.wordcloud.WordCloud object at 0x000001E9C78F7FD0>
w.to_file("wordcloud.png")


w = wordcloud.WordCloud(font_path="msyh.ttc", background_color = "green")
w.generate(" ".join(jieba.lcut(s)))
w.to_file("wordcloud.png")


w.generate("Python123 is a leading platform for Python programming") # <wordcloud.wordcloud.WordCloud object at 0x000001E9B3F82D68>
w.to_file("wordcloud.png")